package com.csd.activity;

import com.csd.view.CarTypePopupwindow;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AuditingActivity extends Activity implements OnClickListener {

	private LinearLayout ll_chooseAnimation, ll_chooseCar;
	private Button bt_replace, bt_sure, bt_cancle;
	private TextView tv_chooseCartype,tv_cartTypeAfter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_auditing);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		bt_replace = (Button) findViewById(R.id.replace);
		bt_replace.setOnClickListener(this);
		ll_chooseAnimation = (LinearLayout) findViewById(R.id.chooseanimation);
		ll_chooseCar = (LinearLayout) findViewById(R.id.choosecar);
		ll_chooseCar.setOnClickListener(this);
		tv_chooseCartype = (TextView) findViewById(R.id.carType);
		bt_cancle = (Button) findViewById(R.id.choose_cancle);
		bt_sure = (Button) findViewById(R.id.choose_sure);
		bt_cancle.setOnClickListener(this);
		bt_sure.setOnClickListener(this);
		tv_cartTypeAfter = (TextView) findViewById(R.id.cartype_after);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.replace:
			ll_chooseAnimation.setVisibility(View.VISIBLE);
			DisplayMetrics dm = new DisplayMetrics();
			dm = this.getApplicationContext().getResources()
					.getDisplayMetrics();
			int screenWidth = dm.widthPixels;
			int screenHeight = dm.heightPixels;
			AnimationSet animationSet = new AnimationSet(true);
			TranslateAnimation animation = new TranslateAnimation(0,
					0, screenHeight, 0);
			animation.setDuration(1000);
			animationSet.addAnimation(animation);
			ll_chooseAnimation.startAnimation(animationSet);
			break;
		case R.id.choosecar:
			CarTypePopupwindow car = new CarTypePopupwindow(
					AuditingActivity.this, tv_chooseCartype, null);
			car.showPopupWindow(tv_chooseCartype);
			break;
		case R.id.choose_cancle:
			ll_chooseAnimation.setVisibility(View.GONE);
			break;
		case R.id.choose_sure:
			tv_cartTypeAfter.setText(tv_chooseCartype.getText());
			ll_chooseAnimation.setVisibility(View.GONE);
			break;
		default:
			break;
		}
	}
}
